﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Revis.VClinicNet.Core.Domain;

namespace Revis.VClinicNet.Core.Domain.Credentials
{
    public class WorkerUser
    {
        public virtual long Id { get; protected set; }
        public virtual string Login { get; protected set; }
        public virtual string Password { get; protected set; }
        public virtual bool IsActive { get; protected set; }
        public virtual WorkerUserRole Role { get; protected set; }
        public virtual Worker RelatedWorker { get; protected set; }

        #region Constructors

        public WorkerUser()
        {
        }

        public WorkerUser(string login, string hashedPassword, Worker related, WorkerUserRole role) :
            this(0, login, hashedPassword, related, role)
        {
        }

        public WorkerUser(long id, string login, string hashedPassword, Worker related, WorkerUserRole role)
        {
            SetUpFields(login, hashedPassword, role);
            if (related == null) {
                throw new ArgumentNullException("Null related worker");
            }
            RelatedWorker = related;
            Id = id;
            IsActive = true;
        }

        #endregion

        #region Public Methods

        public virtual void Change(string login, string password, WorkerUserRole role)
        {
            SetUpFields(login, password, role);
        }

        public virtual void SetInactive()
        {
            SetActivity(false);
        }

        public virtual void SetActive()
        {
            SetActivity(true);
        }

        public virtual void SetActivity(bool isActive)
        {
            IsActive = isActive;
        }

        #endregion

        #region Private Methods

        private void SetUpFields(string login, string hashedPassword, WorkerUserRole role)
        {
            if (login == null) {
                throw new ArgumentNullException("Null login");
            }
            if (hashedPassword == null) {
                throw new ArgumentNullException("Null hashedPassword");
            }
            Login = login;
            Password = hashedPassword;
            Role = role;
        }

        #endregion
    }
}
